﻿package com.crl.module.logging
{
    
    
    /**
     * Static class containing constants for use in the level property.
     */
    public class LoggerLevel
    {
        public var value:int;
		public var name:String;
        public function LoggerLevel( value:int , name:String )
        {
            this.value=value;
			this.name=name;
        }
        
        /**
         * Intended to force a target to process all messages (1).
         */
        public static const ALL:LoggerLevel = new LoggerLevel( 1 , "ALL" ) ;
        
        /**
         * Designates informational level messages that are fine grained and most helpful when debugging an application (2).
         */
        public static const DEBUG:LoggerLevel = new LoggerLevel( 2 , "DEBUG" ) ;
        
        /**
         * Designates error events that might still allow the application to continue running (8).
         */    
        public static const ERROR:LoggerLevel = new LoggerLevel( 8 , "ERROR" ) ;
        
        /**
         * Designates events that are very harmful and will eventually lead to application failure (16).
         */
        public static const FATAL:LoggerLevel = new LoggerLevel( 16 , "FATAL" ) ;
        
        /**
         * Designates informational messages that highlight the progress of the application at coarse-grained level (4).
         */
        public static const INFO:LoggerLevel = new LoggerLevel( 4 , "INFO" ) ;
        
        /**
         * A special level that can be used to turn off logging (0).
         */
        public static const NONE:LoggerLevel = new LoggerLevel( 0 , "NONE" ) ;
        
        /**
         * Designates events that could be harmful to the application operation (6).
         */    
        public static const WARN:LoggerLevel = new LoggerLevel( 6 , "WARN" ) ;
        
        public function equals( o:* ):Boolean
        {
            if ( o == this )
            {
                return true ;
            }
            else if ( o is LoggerLevel )
            {
                return ( (o as LoggerLevel).name == name) && ( (o as LoggerLevel).value == value) ;
            }
            else
            {
                return false ;
            }
        }
        
        public static function getLevel( value:int ):LoggerLevel 
        {
            var levels:Array = [ ALL, DEBUG, ERROR, FATAL, INFO, NONE, WARN ] ;
            var l:int = levels.length ;
            while( --l > -1 )
            {
                if ( int(levels[l] as LoggerLevel) == value )
                {
                    return levels[l] ; 
                }
            }
            return null ;
        }
        
        public static function isValidLevel( level:LoggerLevel ):Boolean 
        {
            var levels:Array = [ ALL, DEBUG, ERROR, FATAL, INFO, NONE, WARN ] ;
            return levels.indexOf( level ) > -1 ;
        }
		
		public function toString():String{
			return "logger";
		}
    }
}